home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1885 < prev    next >
Encoding:
Text File  |  1996-08-06  |  879 b   |  35 lines

  1. Path: acs3.acs.ucalgary.ca!hdang
  2. From: hdang@acs3.acs.ucalgary.ca (Hanna Dang)
  3. Newsgroups: comp.lang.c++
  4. Subject: Overloading conversion
  5. Date: 13 Jan 1996 20:02:39 GMT
  6. Organization: The University of Calgary
  7. Message-ID: <4d934v$10hs@ds2.acs.ucalgary.ca>
  8. NNTP-Posting-Host: hdang@acs3.acs.ucalgary.ca
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. Is there a way to overload functions such that certain
  12. functions are called depending on the context the object are
  13. used. For example,
  14.  
  15. class T {
  16.   public:
  17.     int& int_value() { modified = TRUE; return value;}
  18.     int int_value() {return value;}
  19.  private:
  20.     int value;
  21.     int modified;
  22. }
  23.  
  24.  
  25. ...
  26.  
  27. T a;
  28. int test = a + 6 // int int_value should be called;
  29. a = 20 // int& int_value should be called.
  30.  
  31. However, this does not work because in both case int& int_value
  32. is called.  Is there another way to find out if value is changed
  33. or it's just inspected.
  34.  
  35.